package com.ruoyi.web.ydz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.ydz.domain.PointsRecord;
import com.ruoyi.web.ydz.service.IPointsRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 用户签到及积分收入记录Controller
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/ydz/record")
public class PointsRecordController extends BaseController
{
    @Resource
    private IPointsRecordService pointsRecordService;

    /**
     * 查询用户签到及积分收入记录列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PointsRecord pointsRecord)
    {
        startPage();
        List<PointsRecord> list = pointsRecordService.selectPointsRecordList(pointsRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户签到及积分收入记录列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:record:export')")
    @Log(title = "用户签到及积分收入记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsRecord pointsRecord)
    {
        List<PointsRecord> list = pointsRecordService.selectPointsRecordList(pointsRecord);
        ExcelUtil<PointsRecord> util = new ExcelUtil<PointsRecord>(PointsRecord.class);
        util.exportExcel(response, list, "用户签到及积分收入记录数据");
    }

    /**
     * 获取用户签到及积分收入记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointsRecordService.selectPointsRecordById(id));
    }

    /**
     * 新增用户签到及积分收入记录
     */
    @PreAuthorize("@ss.hasPermi('ydz:record:add')")
    @Log(title = "用户签到及积分收入记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PointsRecord pointsRecord)
    {
        return toAjax(pointsRecordService.insertPointsRecord(pointsRecord));
    }

    /**
     * 修改用户签到及积分收入记录
     */
    @PreAuthorize("@ss.hasPermi('ydz:record:edit')")
    @Log(title = "用户签到及积分收入记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsRecord pointsRecord)
    {
        return toAjax(pointsRecordService.updatePointsRecord(pointsRecord));
    }

    /**
     * 删除用户签到及积分收入记录
     */
    @PreAuthorize("@ss.hasPermi('ydz:record:remove')")
    @Log(title = "用户签到及积分收入记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointsRecordService.deletePointsRecordByIds(ids));
    }

    /**
     * 用户签到
     */
    @PreAuthorize("@ss.hasPermi('ydz:record:add')")
    @Log(title = "用户签到")
    @RequestMapping("/signIn")
    public AjaxResult signIn(){
        return pointsRecordService.signIn();
    }

    /*
    * 查询用户签到记录 当前自然星期
    * */
    @Log(title = "查询用户签到记录")
    @RequestMapping("/getSignInRecord")
    public AjaxResult getSignInRecord(){
        return pointsRecordService.getSignInRecord();
    }

}
